package com.bnzj.core.persistence.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.bnzj.core.util.FbConstant;
import org.springframework.format.annotation.DateTimeFormat;

import com.bnzj.core.json.DateDeserializer;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@ToString
@Schema(description="基本实体")
@MappedSuperclass
public abstract class BaseEntity implements Serializable {
	private static final long serialVersionUID = 6261531903668051386L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Schema(description="唯一标识")
	protected Long id;// 主键

	@Column(name = "creator", updatable = false)
    @Schema(description="创建人ID")
	protected String creator;// 创建人账号

    @Column(name = "creator_name", updatable = false)
    @Schema(description="创建人名称")
    protected String creatorName;// 创建人

	@Column(name = "create_time", updatable = false)
	@Temporal(TemporalType.TIMESTAMP)
	@DateTimeFormat(pattern = FbConstant.DATETIME_FORMAT)
	@JsonDeserialize(using = DateDeserializer.class)
	@JsonFormat(pattern = FbConstant.DATETIME_FORMAT, timezone = "GMT+8")
    @Schema(description="创建时间")
	protected Date createTime;// 创建时间

	@Column(name = "modify_by")
    @Schema(description="修改人ID")
	protected String modifyBy;// 修改人账号

    @Column(name = "modify_name")
    @Schema(description="修改人名称")
    protected String modifyName;// 修改人

	@Column(name = "modify_time")
	@Temporal(TemporalType.TIMESTAMP)
	@DateTimeFormat(pattern = FbConstant.DATETIME_FORMAT)
	@JsonDeserialize(using = DateDeserializer.class)
	@JsonFormat(pattern = FbConstant.DATETIME_FORMAT, timezone = "GMT+8")
    @Schema(description="修改时间")
	protected Date modifyTime;// 修改时间
	
	public void setBaseData(BaseEntity entity) {
        this.setCreateTime(entity.getCreateTime());
        this.setCreator(entity.getCreator());
        this.setCreatorName(entity.getCreatorName());
        this.setModifyBy(entity.getModifyBy());
        this.setModifyName(entity.getModifyName());
        this.setModifyTime(entity.getModifyTime());
	}
	
}
